<%String nav="result"; %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.google.appengine.api.users.*" %>
<%
  UserService userService = UserServiceFactory.getUserService();
  User user = userService.getCurrentUser();
  String authURL = (user != null) ? userService.createLogoutURL(request.getRequestURI()): userService.createLoginURL(request.getRequestURI());
%><!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Show Minifier - Visual web page compressor</title>
    <link type="text/css" rel="stylesheet" href="/css/project.css" />
  </head>
  <body>
  <div class="page">
  <div class="head">
    <div class="signin">
      <% if (user != null) { %>
         <%= user.getEmail() %> | <a href="/settings">settings</a> | 
      <% } %>
      <a href="<%= authURL %>">
        <% if (user != null) { %>Log out<% } else  { %>Log in<% } %>
      </a>
    </div>
    <h1>
        Show Minifier
    </h1>
    <ul class="nav">
    	<li><a <% if(nav.equals("home")){%>class="selected" <%}%>href="/">Home</a>
        <li><a <% if(nav.equals("test")){%>class="selected" <%}%>href="/test">New Test</a>
        <li><a <% if(nav.equals("result")){%>class="selected" <%}%>href="/result">Test Result</a>
        <li><a href="http://code.google.com/p/showminifier">Download</a>
    	<!--li><a <% if(nav.equals("performance")){%>class="selected"<%}%> href="/performance">Performance</a-->
    	<!--li><a <% if(nav.equals("help")){%>class="selected"<%}%> href="/help">Help</a-->
        <li><a href="http://groups.google.com/group/showminifier">Forums</a>
    </ul>
    </div>
<div class="body">
    <h1>Performance evaluation</h1>
    <div id="result"></div>
<%
String key = request.getParameter("key");
String reflow = request.getParameter("reflow");
java.util.Date now = new java.util.Date();
long d = now.getTime();
String url = "/display?key=" + key + (reflow == null || !reflow.equals("true") ? "" : "&reflow=true" ) + "&performance=true&sd=" + d;
%>
	<h3>Original page</h3>
    <iframe id="original-frame" src="<%=url%>&view=o" width="100%" height="280"></iframe>
	<h3>Minified page</h3>
	<iframe id="minified-frame" src="<%=url%>" width="100%" height="280"></iframe>
</div>
<%@ include file="include/foot.jsp"%>
<script src="/js/display.js"></script>
<script>
  	(function(){
		var report = {},
			iframes = ['original-frame','minified-frame'],
			init = {};
		each(iframes,function(i,v){
			init[v] = false;
			addEvent($(v),'load',function(e){
				init[v] = true;
			});
		});
		//Opera, Safira and Chrome have some problem with unload event that page sent request to server.
		addEvent(window,'unload',function(e){
			sendBeacon();
			var onunload = true;
			each(init,function(i,v){
				if(!v){
					onunload = v;
					return false;
				}
			});
			if(!onunload){
				if(!getCookie('alert')){
					alert("Some domain set top.location to replace url.This reminder only alert at once.")
					setCookie('alert','false',{expires:new Date("January 12, 2050")})
				}
				self.location.href = "/performance/detail?key=<%=key%>";
			}
		});
		
	}());
</script>
</div>
